package com.baozun.houji.order.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.baozhun.mall.common.arouter.RoutePath
import com.baozhun.mall.common.base.BaseActivity
import com.baozhun.mall.common.util.Constants
import com.baozhun.mall.common.util.StatusBarUtil
import com.baozun.houji.order.R
import com.baozun.houji.order.fragment.OrderListFragment
import com.baozhun.mall.common.model.enums.OrderStatus
import com.baozun.houji.order.viewmodel.OrderListViewModel
import com.baozun.houji.order.databinding.ActivityOrderListBinding

/**
 * @Title：订单列表页
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/20
 * @Version：1.0.0
 */
@Route(path = RoutePath.Order.ORDER_LIST)
class OrderListActivity : BaseActivity<OrderListViewModel, ActivityOrderListBinding>(), ViewPager.OnPageChangeListener {

    private val orderFragmentList =
        arrayListOf<Fragment>(
            OrderListFragment.newInstance(orderStatus = OrderStatus.ALL),
            OrderListFragment.newInstance(orderStatus = OrderStatus.WAIT_DELIVERY),
            OrderListFragment.newInstance(orderStatus = OrderStatus.WAIT_SEND),
            OrderListFragment.newInstance(orderStatus = OrderStatus.WAIT_RECEIVE),
        )
    private val orderStatus by lazy { intent?.getSerializableExtra(Constants.Order.ORDER_STATUS) as OrderStatus }

    companion object {
        fun start(context: Context, orderStatus: OrderStatus) {
            var intent = Intent(context, OrderListActivity::class.java)
            intent.putExtra(Constants.Order.ORDER_STATUS, orderStatus)
            context.startActivity(intent)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setColor(this, getColor(android.R.color.transparent))
        StatusBarUtil.setTransparentForImageView(this, mDataBinding.titleBar)
        mDataBinding.orderTabLayout.setViewPager(
            mDataBinding.orderListViewpager,
            arrayOf(OrderStatus.ALL.desc, OrderStatus.WAIT_DELIVERY.desc, OrderStatus.WAIT_SEND.desc, OrderStatus.WAIT_RECEIVE.desc),
            this,
            orderFragmentList
        )
        mDataBinding.orderTabLayout.currentTab = orderStatus.ordinal
        mDataBinding.orderListViewpager.addOnPageChangeListener(this)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.tv_order_search -> OrderSearchActivity.start(this)
        }
    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
    }

    override fun onPageSelected(position: Int) {
    }

    override fun onPageScrollStateChanged(state: Int) {

    }


}